/**
 * 
 */
package com.wct;

import serverinterfaces.InterfacesPrx;
import serverinterfaces.InterfacesPrxHelper;
import Ice.InitializationData;

/**
 * @author Administrator
 *
 */
public class IceProxyFactory {

	private Ice.Communicator ic = null;

	private boolean icInit = false;

	private InterfacesPrx proxy;

	public InterfacesPrx getInstance() {
        if (!icInit)
        {
            initIc();
            icInit = true;
        }

        if (proxy == null)
        {

            try
            {
                Ice.ObjectPrx base = ic.propertyToProxy("AccessSession.Proxy");
                proxy = InterfacesPrxHelper.checkedCast(base);

            }
            catch (Exception e)
            {
                // ignore
                e.printStackTrace();
            }
        }
//         if (proxy == null) {
//
//         Ice.Communicator ic = null;
//         ic = Ice.Util.initialize();
//         Ice.ObjectPrx base = ic
//         .stringToProxy("EnterpriseContact:tcp -p 10000 -h localhost");
//         proxy = InterfacesPrxHelper.checkedCast(base);
//
//
//
//         }
        return proxy;
    }

	private void initIc() {
		InitializationData initData = new InitializationData();
		initData.properties = Ice.Util.createProperties();
        
        initData.properties.setProperty("AccessSession.Proxy", "accesssession");
        initData.properties.setProperty("Ice.Default.Locator",
            "ContactIceGrid/Locator:tcp -h 120.27.109.100 -p 12001 -t 10000");
        
        initData.properties.setProperty("Ice.Default.SlicedFormat", "1");
		ic = Ice.Util.initialize(initData);
	}

}
